﻿using KELT.KELTObjects.ViewportObjectModel;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Media.Animation;
using System.Windows.Media.Media3D;

namespace KELT.Animation.Animation2D
{

    public class ZoomAnimation : IAnimation
    {
        private DoubleAnimation widthAni;
        private DoubleAnimation heightAni;

        private double zoomPoint1 = 1;
        private double zoomPoint2 = 2;


        public ZoomAnimation()
        {

            widthAni = new DoubleAnimation();
            heightAni = new DoubleAnimation();

        }
        public override void SetAnimation(Storyboard myStoryboard, ViewportObj obj)
        {
            animationName = "확대/축소";

            double animationTime = endTime - startTime;

            widthAni.Duration = new Duration(TimeSpan.FromSeconds(animationTime));
            widthAni.BeginTime = TimeSpan.FromSeconds(startTime);
            widthAni.From = zoomPoint1;
            widthAni.To = zoomPoint2;

            Storyboard.SetTargetProperty(widthAni, new PropertyPath(ScaleTransform3D.ScaleXProperty));
            Storyboard.SetTargetName(widthAni, AnimationInfo.ANIMATION_SCALE + obj.getIndexNumber());
            myStoryboard.Children.Add(widthAni);





            heightAni.Duration = new Duration(TimeSpan.FromSeconds(animationTime));
            heightAni.BeginTime = TimeSpan.FromSeconds(startTime);
            heightAni.From = zoomPoint1;
            heightAni.To = zoomPoint2;

            Storyboard.SetTargetProperty(heightAni, new PropertyPath(ScaleTransform3D.ScaleYProperty));
            Storyboard.SetTargetName(heightAni, AnimationInfo.ANIMATION_SCALE + obj.getIndexNumber());
            myStoryboard.Children.Add(heightAni);

        }
        public void setOption(double option1, double option2)
        {
            this.zoomPoint1 = option1;
            this.zoomPoint2 = option2;

            if (widthAni != null & heightAni != null)
            {
                widthAni.From = zoomPoint1;
                widthAni.To = zoomPoint2;

                heightAni.From = zoomPoint1;
                heightAni.To = zoomPoint2;
            }
        }


        public override void changeAnimation(Storyboard myStoryboard)
        {
            myStoryboard.Children.Remove(widthAni);
            myStoryboard.Children.Remove(heightAni);

            widthAni.Duration = TimeSpan.FromSeconds(endTime - startTime);
            widthAni.BeginTime = TimeSpan.FromSeconds(startTime);

            heightAni.Duration = TimeSpan.FromSeconds(endTime - startTime);
            heightAni.BeginTime = TimeSpan.FromSeconds(startTime);

            myStoryboard.Children.Add(widthAni);
            myStoryboard.Children.Add(heightAni);

        }


        public override void deleteAnimation(Storyboard myStoryboard)
        {
            myStoryboard.Children.Remove(widthAni);
            myStoryboard.Children.Remove(heightAni);
        }
    }
}
